#pragma once

#include <QAbstractTableModel>

#include "table.h"

QString getUsbTypeString(UsbType type);
QString getSupportedString(bool supported);

class TableModel : public QAbstractTableModel
{
    Q_OBJECT
public:

    enum ColumnType {
        Column_SN,
        Column_Name,
        Column_Hotspot,
        Column_Usb,
        Column_Note,
        Column_NUM
    };

    explicit TableModel(QObject *parent = nullptr);
    ~TableModel();

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;

    bool load(const QString &fileName, Table::SaveFormat format = Table::JsonFormat, bool clearOldData = true);
    bool save(const QString &fileName, Table::SaveFormat format = Table::JsonFormat);

private:
    Table *m_datas;

};
